﻿using Shoy.Wcf.Client.UseTest;
using Shoy.Wcf.Contract;
using System;
using System.Threading;
using System.Threading.Tasks;

namespace Shoy.Wcf.Client
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            for (var i = 0; i < 100; i++)
            {
                WcfHelper.Instance.Call<IHelloContract>(t =>
                {
                    var msg = t.Hello("shoy");
                    Console.WriteLine($"{DateTime.Now:u}:{msg}");
                }, Console.WriteLine);
                Thread.Sleep(1500);
            }

            //StressTest();

            Console.ReadLine();
        }

        /// <summary> 压力测试 </summary>
        private static void StressTest()
        {
            const int iteraction = 5000;
            var task1 = Task.Factory.StartNew(() =>
            {
                var result = CodeTimer.Time("wcf单站点压力测试", iteraction, () =>
                {
                    WcfHelper.Instance.Call<IHelloContract>(t =>
                    {
                        var msg = t.Hello("test");
                    }, null, "http://192.168.11.29:8011");
                    return true;
                });
                Console.WriteLine(result);
            });

            var task2 = Task.Factory.StartNew(() =>
            {
                var result1 = CodeTimer.Time("wcf分布式站点压力测试", iteraction, () =>
                {
                    WcfHelper.Instance.Call<IHelloContract>(t =>
                    {
                        var msg = t.Hello("test");
                    }, null, "http://192.168.11.29:8011", "http://192.168.11.29:8012", "http://192.168.11.29:8013");
                    return true;
                });

                Console.WriteLine(result1);
            });
            Task.WaitAll(task1, task2);
        }
    }
}
